package com.xuelang.pipeline.entry.pipeline;

import com.xuelang.pipeline.app.pipeline.GroupService;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.pipeline.IGroupService;
import com.xuelang.pipeline.client.pipeline.dto.GroupDTO;
import com.xuelang.pipeline.client.pipeline.dto.GroupQuery;
import com.xuelang.pipeline.client.pipeline.dto.PipelineGroupQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 流水线分组服务web控制类
 *
 * @author xiwen.zxg
 * @since 2024/5/15
 */
@Slf4j
@RestController
@RequestMapping("/group")
public class GroupController implements IGroupService {

    @Autowired
    private GroupService groupService;

    @Override
    public ApiResult<PageRecord<GroupDTO>> pageGroupList(PageParam<GroupQuery> dtoPageParam) {
        return ApiResult.success(groupService.pageList(dtoPageParam));
    }

    @Override
    public ApiResult<List<GroupDTO>> conditionalGroupList(GroupQuery groupQuery) {
        return ApiResult.success(groupService.list(groupQuery));
    }

    @Override
    public ApiResult<Boolean> addGroup(GroupDTO groupDTO) {
        return ApiResult.success(groupService.add(groupDTO));
    }

    @Override
    public ApiResult<Boolean> batchSaveOrUpdate(List<GroupDTO> groupDTOList) {
        return ApiResult.success(groupService.batchSaveOrUpdate(groupDTOList));
    }

    @Override
    public ApiResult<Boolean> updateGroup(GroupDTO groupDTO) {
        return ApiResult.success(groupService.update(groupDTO));
    }

    @Override
    public ApiResult<Boolean> deleteGroup(String uuid) {
        return ApiResult.success(groupService.delete(uuid));
    }

    @Override
    public ApiResult<GroupDTO> queryGroup(String uuid) {
        return ApiResult.success(groupService.query(uuid));
    }

    @Override
    public ApiResult<Boolean> modifyPipelineGroups(@Valid PipelineGroupQuery query) {
        return ApiResult.success(groupService.modifyPipelineGroups(query));
    }

    @Override
    public ApiResult<Boolean> addFavoritePipeline(String pipelineCode) {
        return ApiResult.success(groupService.addFavoritePipeline(pipelineCode));
    }

    @Override
    public ApiResult<Boolean> removeFavoritePipeline(String pipelineCode) {
        return ApiResult.success(groupService.removeFavoritePipeline(pipelineCode));
    }
}